/**
 * 
 */
package org.dragonfire.dasm.directives;

import java.util.ArrayList;

import org.dragonfire.dasm.Command;
import org.dragonfire.dasm.Listing;
import org.dragonfire.dasm.DirectiveManager.Directive;
import org.dragonfire.dasm.instr.InstructionTable;

/**
 * <code>#REGISTER</code> adds <code>Register</code> definitions to the
 * instruction table for use with instructions. There are 3 parameters, none are
 * optional.<br />
 * <br />
 * Format:<br />
 * <code>#REGISTER <i>&lt;name&gt;</i>,<i>&lt;classID&gt;</i>,<i>&lt;bits&gt;</i></code><br />
 * <br />
 * Parameters:<br />
 * <table>
 * <tr>
 * <td><code>name</code></td>
 * <td>(String) The name of the register.</td>
 * </tr>
 * <tr>
 * <td><code>classID</code></td>
 * <td>(Integer) The register's class.</td>
 * </tr>
 * <tr>
 * <td><code>bits</code></td>
 * <td>(String) The binary string that is substituted into Instructions.</td>
 * </tr>
 * </table><br />
 * Errors:<br />
 * <table>
 * <tr>
 * <td><code>ERROR_NOT_ENOUGH_ARGS</code></td>
 * <td>Thrown if the number of arguments is less than 3.</td>
 * </tr>
 * <tr>
 * <td><code>ERROR_STRING_REQUIRED</code></td>
 * <td>Thrown if <code>name</code> or <code>bits</code> are not strings</td>
 * </tr>
 * <tr>
 * <td><code>ERROR_INT_REQUIRED</code></td>
 * <td>Thrown if <code>classID</code> is not an integer</td>
 * </tr>
 * </table>
 * 
 * @see org.dragonfire.dasm.instr.Instruction
 * @see org.dragonfire.dasm.instr.Register
 * @see InstructionTable
 * @author Darth Android
 * @version 2.0
 */
public class Register extends Directive {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ArrayList<Listing> pass1(Command c) {
		// extract parameters
		String name = evalString(c.getParam(0));
		int classID = evalInt(c.getParam(1));
		String bits = evalString(c.getParam(2));
		// add the register
		getCompiler().getInstructions().addRegister(name, classID, bits);
		return null;
	}
}